<?php

namespace app\shop\controller;

use app\shop\exception\ParamsErrorException;
use app\shop\library\ShopAuth;
use app\shop\logic\TaskLogic;
use think\response\Json;
use app\shop\exception\FailException;
use app\shop\library\ShopLogHelper;
use app\shop\logic\OrderLogic;
use app\shop\validate\OrderValidate;
use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
use Throwable;

class TaskController extends BaseController
{
    public function __construct()
    {
        parent::__construct();

        $this->logic = new TaskLogic();
    }
    protected array $noNeedLogin = [];


    /**
     * 订单列表
     * @return Json
     * @throws ParamsErrorException
     */
    public function list(): Json
    {
        $params = $this->postInput(true);
        $user = ShopAuth::instance()->getUser();
        $params['user_id'] = $user->id;
        if(!isset($params['type'])){
            $params['type'] = 1;
        }
        $result = $this->logic->list($params);
        return $this->success($result);
    }

    public function detail(): Json
    {
        $params = $this->postInput(true);
        $user = ShopAuth::instance()->getUser();
        $params['user_id'] = $user->id;
        $result = $this->logic->detail($params);
        return $this->success($result);
    }

    public function submit()
    {
        $params = $this->postInput(true);
        $user = ShopAuth::instance()->getUser();
        $params['user_id'] = $user->id;
        $result = $this->logic->submit($params);
        return $this->success($result['msg']);
    }

}